<?php
defined('IN_TS') or die('Access Denied.');
$userid = aac('user')->isLogin();
switch($ts){

	case "":
		//发起投票
		
		$title = '发起投票';
		include template('add');
		break;
		
	case "do":
		$topic = trim($_POST['topic']);
		$content = tsClean($_POST['content']);
		$arrOption = $_POST['option'];//投票选项
		$type = intval($_POST['type']);
		
		if (intval ( $TS_USER ['isadmin'] ) == 0) {
			// 过滤内容开始
			aac ( 'system' )->antiWord ( $topic );
			aac ( 'system' )->antiWord ( $content );
			// 过滤内容结束
		}

		//处理选项
		foreach($arrOption as $k=>$v){
				$arrOption[$k]=trim($v);
		}
		$addtime= trim($_POST['addtime']);
		$endtime = trim($_POST['endtime']);
		
		$voteid = $new['vote']->create('vote',array(
				'userid'=>$userid,
				'topic'=>$topic,
				'content'=>$content,
				'addtime'=>$addtime,
				'endtime' =>$endtime,
		));
		
		//插入选项
		foreach($arrOption as $k=>$v){
			if($v){
				$new['vote']->create('vote_option',array(
						'voteid'=>$voteid,
						'name' =>$v,
						'count_vote'=>0,
						'type'=>$type,
				));
			}
		}
		

		header('Location:'.tsUrl('vote','show',array('id'=>$voteid)));
		break;
}